//
//  LGComposeTool.m
//  微博
//
//  Created by MS on 15-12-24.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGComposeTool.h"
#import "MJExtension.h"
#import "LGHttpTool.h"
#import "LGComposeParam.h"
#import "LGUploadParama.h"
@implementation LGComposeTool
+(void)composeWithStatus:(NSString *)status success:(void (^)())success failure:(void (^)(NSError *error))failures
{
    
    LGComposeParam * param = [LGComposeParam parama];
    param.status = status;
    [LGHttpTool POST:@"https://api.weibo.com/2/statuses/update.json" parameters:param.keyValues success:^(id responseObject) {
        
        if (success) {
            success();
        }
    } failure:^(NSError *error) {
        if (failures) {
            failures(error);
        }
    }];
    
}

+(void)composeWithStatus:(NSString *)status image:(UIImage *)image success:(void(^)())success failure:(void(^)(NSError * error))failures
{
    
    LGComposeParam * param = [LGComposeParam parama];
    param.status = status;
    
    LGUploadParama * upparama = [[LGUploadParama alloc] init];
    upparama.data = UIImagePNGRepresentation(image);
    upparama.name = @"pic";
    upparama.fileName = @"picture.png";
    upparama.mimeType = @"image/png";
    
    [LGHttpTool Upload:@"https://upload.api.weibo.com/2/statuses/upload.json" parameters:param.keyValues uploadParama:upparama success:^{
        if (success) {
            success();
        }
    } failure:^(NSError *error) {
        if (failures) {
            
            failures(error);
        }
    }];
    
}

@end
